conf = require("../config")
if not conf.lazygit.enabled then return {} end

local function find_project_root()
  local current_file = vim.fn.expand("%:p")
  if current_file == "" then
    current_file = vim.fn.getcwd()
  end
  local root_patterns = { "__nvim_project_root", ".git" }
  local root = vim.fs.dirname(vim.fs.find(root_patterns, {
    path = current_file,
    upward = true,
    stop = vim.loop.os_homedir(),
  })[1]) or vim.fn.getcwd()
  return root
end

return {
  "kdheepak/lazygit.nvim",
  -- optional for floating window border decoration
  dependencies = {
  "nvim-lua/plenary.nvim",
  },
  cmd = {
    "LazyGit",
    "LazyGitConfig",
    "LazyGitCurrentFile",
    "LazyGitFilter",
    "LazyGitFilterCurrentFile",
  },
  keys = {
    {",gg", function ()
      local root = find_project_root()
      vim.cmd("cd " .. root)
      vim.cmd("LazyGit")
    end, mode = "n"},
  },
}
